// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SnapObjects.Expressions
{
    public class EvaluateMethodMetaParser : MethodMetaParser<EvaluateResult, ParameterInfo>
    {
        public new IDictionary<string, EvaluateMethodMetadata> GetMethodMeta(Type type,
            object instance = null)
        {
            var metadata = base.GetMethodMeta(type, instance);

            return metadata.ToDictionary(x => x.Key, x => new EvaluateMethodMetadata(x.Value));
        }

        protected override MethodDataInfo<EvaluateResult, ParameterInfo> GenerateMethod(
            MethodInfo method,
            List<MethodParamInfo<ParameterInfo>> paramInfos,
            int variableParamIndex,
            int optionalParamIndex)
        {
            return new EvalMethodDataInfo(
                method.Name,
                new EvaluateResult(method),
                paramInfos,
                variableParamIndex,
                optionalParamIndex);
        }

        protected override MethodParamInfo<ParameterInfo> GenerateParam(
            ParameterInfo parameter, bool isNotNull)
        {
            return new MethodParamInfo<ParameterInfo>(
                parameter.Name,
                parameter,
                parameter.ParameterType,
                isNotNull,
                parameter.IsOptional,
                parameter.DefaultValue);
        }
    }
}
